package com.sjc.counter.v1;


import com.sjc.counter.entity.RequestInfo;
import org.apache.commons.lang3.StringUtils;

/**
 * @Classname MetricsCollector
 * @Description 负责提供 API，来采集接口请求的原始数据
 * @Date 2020/5/1 13:45
 * @Created by SangJiacun
 */
public class MetricsCollector {
    // 基于接口而非实现编程
    private MetricsStorage metricsStorage;

    // 依赖注入
    public MetricsCollector(MetricsStorage metricsStorage) {
        this.metricsStorage = metricsStorage;
    }

    //用一个函数代替最小原型中的两个函数
    public void recordRequest(RequestInfo requestInfo){
        if(null == requestInfo || StringUtils.isBlank(requestInfo.getApiName())){
            return ;
        }
        metricsStorage.saveRequestInfo(requestInfo);
    }
}
